/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 后台任务
 * @Description *
 * @Package concurrent.mthread.daemon
 * @Since 2021/7/27 2:02 下午
 */
package concurrent.mthread.daemon;

import java.text.MessageFormat;

public class Daemon implements Runnable {
    /**
     * @Description 线程数组
     * @Author chentl
     * @Create: 2021/7/27 2:02 下午
     */
    private Thread[] t = new Thread[10];

    @Override
    public void run() {
        //启动 5 个非后台线程
        for (int i = 0; i < t.length; i++) {
            t[i] = new Thread(new DaemonSpawn());
            t[i].start();
            System.out.println(MessageFormat.format("DaemonSpan {0} started.", i));
        }

        //如果是后台线程  则输出
        for (int i = 0; i < t.length; i++)
            System.out.println(MessageFormat.format("t[{0}].isDaemon() = {1} .", i, t[i].isDaemon()));

        //释放资源
        while (true)
            Thread.yield();
    }
}
